package per.jdz.retryer.predicate;

import java.util.List;
import java.util.function.Predicate;

public class OrPredicate implements IPredicate {
    // 封装多个 Predicate
    private final List<Predicate> predicates;

    public OrPredicate(List<Predicate> predicates) {
        this.predicates = predicates;
    }

    @Override
    public boolean apply(Object input) {
        for (Predicate predicate : predicates) {
            // 一旦有一个为 true 则直接返回
            if (((IPredicate) predicate).apply(input)) {
                return true;
            }
        }
        return false;
    }
}
